package Demo16_30.Test26;

/**
 * Created by 14229 on 2020/1/31.
 */
public class NumTask  implements Runnable{

    private  int num = 100;
    Object obj = new Object();

    @Override
    public void run() {
        while (true){
            synchronized (obj){
                if(num>0){
                    num--;
                    System.out.println(Thread.currentThread().getName()+" 出票成功 现在余票"+num+"张");
                    try {
                        Thread.sleep(2);
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                }else {
                    break;
                }
            }
        }
    }
}
